From 49eaced1be02d1d69bea8033cfc59d16eaeb36d2 Mon Sep 17 00:00:00 2001 From: robertl Date: Sat, 26 Jun 2004 04:55:35 +0000 Subject: [PATCH] Sort help strings on output to make them slightly less incomprehensible. :-) --- gpsbabel/Makefile | 2 +- gpsbabel/internal_styles.c | 1 + gpsbabel/mkstyle.sh | 4 ++- gpsbabel/vecs.c | 53 +++++++++++++++++++++++++++++--------- 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/gpsbabel/Makefile b/gpsbabel/Makefile index fa87d7eb0..c79071169 100644 --- a/gpsbabel/Makefile +++ b/gpsbabel/Makefile @@ -243,4 +243,4 @@ jeeps/gpsutil.o: jeeps/gpsutil.c jeeps/gps.h defs.h queue.h \ jeeps/gpsrqst.h jeeps/gpsinput.h jeeps/gpsproj.h jeeps/gpsnmeafmt.h \ jeeps/gpsnmeaget.h internal_styles.c: mkstyle.sh style/README.style style/arc.style style/csv.style style/custom.style style/dna.style style/fugawi.style style/gpsdrive.style style/gpsman.style style/mapconverter.style style/mxf.style style/nima.style style/s_and_t.style style/saplus.style style/tabsep.style style/xmap.style style/xmapwpt.style - ./mkstyle.sh > internal_sytles.c || (rm -f dep ; exit 1) + ./mkstyle.sh > internal_styles.c || (rm -f dep ; exit 1) diff --git a/gpsbabel/internal_styles.c b/gpsbabel/internal_styles.c index e7e046b6e..ab5bc6143 100644 --- a/gpsbabel/internal_styles.c +++ b/gpsbabel/internal_styles.c @@ -555,3 +555,4 @@ static char xmapwpt[] = ; #include "defs.h" style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "tabsep", tabsep } , { "saplus", saplus } , { "s_and_t", s_and_t } , { "nima", nima } , { "mxf", mxf } , { "mapconverter", mapconverter } , { "gpsman", gpsman } , { "gpsdrive", gpsdrive } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "csv", csv } , { "arc", arc } , {0,0}}; +size_t nstyles = 15; diff --git a/gpsbabel/mkstyle.sh b/gpsbabel/mkstyle.sh index 52c799a5c..418e60f05 100755 --- a/gpsbabel/mkstyle.sh +++ b/gpsbabel/mkstyle.sh @@ -3,6 +3,7 @@ echo "/* This file is machine-generated from the contents of style/ */" echo "/* by mkstyle.sh. Editing it by hand is an exeedingly bad idea. */" echo +nstyles="0" for i in style/*.style do A=`basename $i | sed "s/.style$//"` @@ -12,8 +13,9 @@ do echo "static char $A[] = " sed 's/\\/\\\\/;s/"/\\"/g;s/\(^.\)/"\1/g;s/\(.$\)/\1\\n"/g' $i echo ";" - + nstyles=`expr $nstyles + 1`; done echo "#include \"defs.h\"" echo "style_vecs_t style_list[] = {$ALIST {0,0}};" +echo "size_t nstyles = $nstyles;" diff --git a/gpsbabel/vecs.c b/gpsbabel/vecs.c index 0fc7ee4de..1bb62affb 100644 --- a/gpsbabel/vecs.c +++ b/gpsbabel/vecs.c @@ -411,32 +411,61 @@ get_option(const char *iarglist, const char *argname) * Display the available formats in a format that's easy for humans to * parse for help on available command line options. */ +static signed int +alpha (const void *a, const void *b) +{ + + const vecs_t *const *ap = a; + const vecs_t *const *bp = b; + + return strcmp((*ap)->name , (*bp)->name); +} + void disp_vecs(void) { vecs_t *vec; style_vecs_t *svec; arglist_t *ap; + int vc; + vecs_t **svp; + int i = 0; #define VEC_FMT " %-20.20s %-.50s\n" - for (vec = vec_list; vec->vec; vec++) { - printf(VEC_FMT, vec->name, vec->desc); - for (ap = vec->vec->args; ap && ap->argstring; ap++) { + /* Get a count from both the vec (normal) and the svec (csv) lists */ + + extern size_t nstyles; + vc = sizeof vec_list / sizeof vec_list[0] -1 + nstyles; + + svp = xcalloc(vc, sizeof(style_vecs_t *)); + + /* Normal vecs are easy; populate the first part of the array. */ + for (vec = vec_list; vec->vec; vec++, i++) { + svp[i] = vec; + } + /* Walk the style list, parse the entries, dummy up a "normal" vec */ + for (svec = style_list; svec->name; svec++, i++) { + xcsv_read_internal_style(svec->style_buf); + svp[i] = xcalloc(1, sizeof **svp); + svp[i]->name = svec->name; + svp[i]->vec = svp[0]->vec; /* Interits xcsv opts */ + svp[i]->desc = xcsv_file.description; + } + + /* Now that we have everything in an array, alphabetize them */ + qsort(svp, vc, sizeof(*svp), alpha); + + for (i=0;iname, svp[i]->desc); + for (ap = svp[i]->vec->args; ap && ap->argstring; ap++) { printf(" %-18.18s %-.50s %s\n", ap->argstring, ap->helpstring, (ap->argtype & ARGTYPE_REQUIRED)?"(required)":""); } } - - /* - * Parse each internal style table in sequence to get the - * help strings from it. - */ - for (svec = style_list; svec->name; svec++) { - xcsv_read_internal_style(svec->style_buf); - printf(VEC_FMT, svec->name, xcsv_file.description); - } + + return; } /* -- 2.30.2